package com.bsth.java8;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.MonthDay;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

/**
 * Created by BSTH on 2017/8/14.
 */
public class Time01 {
	public static void main(String[] args) {
		//现在日期
		LocalDate localDate = LocalDate.now();
		System.out.println("localTime:"+localDate);
		//格式化
		System.out.println(LocalDate.of(2017, 8, 14));
		//格式化
		System.out.println(LocalDate.parse("2017-08-14"));
		//今天加一天
		System.out.println(localDate.plusDays(1));
		//今天减去一个月
		System.out.println(localDate.minusMonths(1));
		System.out.println(localDate.minus(1, ChronoUnit.MONTHS));
		//获取今天是星期几，一个月的哪一天
		System.out.println(localDate.getDayOfMonth());
		System.out.println(localDate.getDayOfWeek());
		//今年是否是闰年
		System.out.println(localDate.isLeapYear());
		//判断两个日期的前后
		System.out.println(LocalDate.parse("2017-08-14").isAfter(LocalDate.parse("2017-07-20")));
		//这个月的第一天
		System.out.println(localDate.withDayOfMonth(1));
		//下个月的第一天
		System.out.println(localDate.with(TemporalAdjusters.firstDayOfNextMonth()));
		//判断今天是否是生日
		LocalDate birthday = LocalDate.parse("1990-08-17");
		MonthDay Mday = MonthDay.of(birthday.getMonth(),birthday.getDayOfMonth());
		MonthDay monthDay = MonthDay.now();
		System.out.println("今天是否是生日："+Mday.equals(monthDay));

		//LocalTime
		//现在时间
		LocalTime localTime = LocalTime.now();
		System.out.println("现在时间："+localTime);
		//格式化时间
		System.out.println(LocalTime.of(12,12));
		System.out.println(LocalTime.parse("12:13"));
	}
}
